// 用户管理相关API
import http from '@/utils/request'

// API基础路径
const API_BASE = '/user'

/**
 * 获取用户列表
 */
export const getUserListApi = (params) => {
  return http.get(`${API_BASE}/list`, params)
}

/**
 * 创建用户
 */
export const createUserApi = (data) => {
  return http.post(`${API_BASE}/create`, data)
}

/**
 * 更新用户
 */
export const updateUserApi = (data) => {
  return http.put(`${API_BASE}/update`, data)
}

/**
 * 删除用户
 */
export const deleteUserApi = (id) => {
  return http.delete(`${API_BASE}/delete`, { id })
}

/**
 * 获取用户详情
 */
export const getUserDetailApi = (id) => {
  return http.get(`${API_BASE}/detail`, { id })
}

/**
 * 获取用户角色
 */
export const getUserRolesApi = (userId) => {
  return http.get(`${API_BASE}/roles`, { userId })
}

/**
 * 分配用户角色
 */
export const assignUserRolesApi = (data) => {
  return http.post(`${API_BASE}/assign-roles`, data)
}

/**
 * 重置用户密码
 */
export const resetPasswordApi = (data) => {
  return http.post(`${API_BASE}/reset-password`, data)
}

/**
 * 修改密码
 */
export const changePasswordApi = (data) => {
  return http.post(`${API_BASE}/change-password`, data)
}

/**
 * 检查用户是否有修改密码权限
 */
export const checkPasswordPermissionApi = (userId) => {
  return http.get(`${API_BASE}/password-permission`, { userId })
}

/**
 * 修改用户状态
 */
export const updateUserStatusApi = (data) => {
  return http.put(`${API_BASE}/status`, data)
}

/**
 * 批量删除用户
 */
export const batchDeleteUsersApi = (ids) => {
  return http.delete(`${API_BASE}/batch-delete`, { ids })
}

/**
 * 导出用户数据
 */
export const exportUserDataApi = (params) => {
  return http.get(`${API_BASE}/export`, params, { responseType: 'blob' })
}

/**
 * 导入用户数据
 */
export const importUserDataApi = (file) => {
  return http.upload(`${API_BASE}/import`, file)
}

/**
 * 上传用户头像
 */
export const uploadAvatarApi = (file) => {
  return http.upload('/upload/avatar', file)
}

/**
 * 更新用户头像
 */
export const updateAvatarApi = (avatarUrl) => {
  return http.put(`${API_BASE}/avatar`, { avatar: avatarUrl })
} 